package bank;

import cash_access.Account;
import cash_access.OverdraftException;

/**
 * Account:
 * our implementation of the abstract account class.
 * depositing, withdrawing and getting the balance are possible actions.
 * @author Rico Flaegel
 * @author Jan Quenzel
 */
public class Account_Impl extends Account{
	public String accountID;
	double money;
	static long account_nr = 2000;
	String owner;
	
	public Account_Impl(String owner) {
		this.money = 0;
		this.owner = owner;
		accountID = ""+account_nr;
		account_nr++;
	}
	@Override
	public void deposit(double amount) {
		if(amount > 0){//only positive amounts are allowed
			money += amount;
		}
	}

	@Override
	public void withdraw(double amount) throws OverdraftException {
		if(amount > 0){//only positive amounts are allowed
			if(money - amount < 0){
				throw new OverdraftException("!!!OverdraftException!!!");
			}else{
				try {
					Thread.sleep(8000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				money-= amount;
			}
		}
	}

	@Override
	public double getBalance() {
		return money;
	}

}
